﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WorkStation.Frameworks.EasyBus.Attributes
{
    /// <summary>
    /// 监听标记（Name，Process，Mq必填，ProcessThreadCount选填，默认为单线程）
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
    public class ListenerAttribute : Attribute
    {
        /// <summary>
        /// 监听器名称
        /// </summary>
        //public string Name { get; set; }

        public string SubscribeName { get; set; }

        /// <summary>
        /// 处理 例：{RouteKeyA}:{Handle1}, {Handle2};{RouteKeyB}:{Handle3}, {Handle3}
        /// </summary>
        //public string Process { get; set; }

        /// <summary>
        /// 处理器名称，多个使用分号隔离
        /// </summary>
        public string HandleName { get; set; }

        /// <summary>
        /// 处理消息线程数
        /// </summary>
        public int ProcessThreadCount { get; set; }

        /// <summary>
        /// 监听队列地址
        /// </summary>
        //public string Mq { get; set; }

        public virtual string[] GetHandleName()
        {
            try 
            {
                return this.HandleName.Split(';').Select(v => v.Trim()).ToArray();
            }
            catch (Exception ce) 
            {
                throw new Exception("输入的字符串格式不正确，例：{HandleNameA};{HandleNameB}，多个使用分号分隔");
            }
        }
    }
}
